home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / networking / pgpuam / headers / librarymanager.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  46.6 KB  |  1,631 lines

  1. /*    File:        LibraryManager.h
  2.  
  3.     Contains:    Minimal declarations you need to use the ASLM.
  4.  
  5.     Copyright:    © 1991-1995 by Apple Computer, Inc., all rights reserved.
  6.  
  7.  
  8. */
  9.  
  10. #ifndef __LIBRARYMANAGER__
  11. #define __LIBRARYMANAGER__
  12.  
  13. #ifndef __STDDEF__
  14. #include <stddef.h>
  15. #endif
  16. #ifndef __STRING__
  17. #include <string.h>
  18. #endif
  19. #ifndef __TYPES__
  20. #include <Types.h>
  21. #endif
  22. #ifndef __CONDITIONALMACROS__
  23. #include <ConditionalMacros.h>
  24. #endif
  25.  
  26. //
  27. // Setup GENERATINGPOWERPC and GENERATING68K variables
  28. //
  29. #ifndef GENERATINGPOWERPC
  30.     #if defined(powerc) || defined(__powerc)
  31.         #define GENERATINGPOWERPC    1
  32.     #else
  33.         #define GENERATINGPOWERPC    0
  34.     #endif
  35. #endif
  36. #ifndef GENERATING68K
  37.     #if defined(powerc) || defined(__powerc)
  38.         #define GENERATING68K        0
  39.     #else
  40.         #define GENERATING68K        1
  41.     #endif
  42. #endif
  43.  
  44. #ifndef GENERATINGCFM
  45.     #define GENERATINGCFM    GENERATINGPOWERPC
  46. #endif
  47.  
  48. //
  49. //    Define the macros that handle adding an empty vtable slot at
  50. //    the beginning of the vtable for SCpp.
  51. //
  52. #define ASLM_COMPATIBLE
  53. #define ASLM_SCDECLARATION(className)
  54. #if defined(__SC__) || defined(THINK_CPLUS) || defined(__MRC__)
  55.     #if !NoDummyVTableSlot
  56.         #undef ASLM_COMPATIBLE
  57.         #undef ASLM_SCDECLARATION
  58.         #define ASLM_COMPATIBLE                                \
  59.             private:                                        \
  60.                 virtual        void DummyVirtualFunction();
  61.                 
  62.         #define ASLM_SCDECLARATION(className)        \
  63.         void className::DummyVirtualFunction() {}
  64.     #endif
  65. #endif
  66.  
  67. //
  68. //    Define SINGLEOBJECT to true if the compiler support SingleObject.
  69. //
  70. #if GENERATING68K && !defined(__SC__) || defined(__MWERKS__)
  71.     #define SINGLEOBJECT    1
  72. #else
  73.     #define SINGLEOBJECT    0
  74. #endif
  75.  
  76. //
  77. //    Define _CDECL as _cdecl only when using Symantec 68k products.
  78. //
  79. #if defined(__SC__) || defined(THINK_CPLUS) || defined(__MRC__)
  80.     #define _CDECL            _cdecl
  81. #else
  82.     #define _CDECL
  83. #endif
  84.  
  85. //
  86. //    Define the Volatile and VOLATILE macros based on the compiler.
  87. //
  88. #define VOLATILE(x)        ((void) &x)
  89. #if GENERATINGPOWERPC || defined(__SC__) || defined(THINK_CPLUS) || defined(__MWERKS__)
  90.     #define Volatile        volatile
  91. #else
  92.     #define Volatile
  93. #endif
  94.  
  95.  
  96. #undef SystemSixOrLater
  97. #define SystemSixOrLater    1
  98.  
  99.  
  100. /*******************************************************************************
  101. ** Some Typedefs and constants
  102. ********************************************************************************/
  103.  
  104. #ifndef NULL
  105. #define NULL        0
  106. #endif
  107.  
  108. //
  109. //    The following are parameter typedefs to force Symantec compilers to pass
  110. //    two byte parameters as four byte parameters so you can call MPW built
  111. //    shared libraries from Symantec built clients.
  112. //
  113. #if GENERATING68K
  114.     typedef    int                OSErrParm;
  115.     typedef unsigned int    BooleanParm;
  116.     typedef int                charParm;
  117.     typedef unsigned int    ucharParm;
  118.     typedef int                shortParm;
  119.     typedef unsigned int    ushortParm;
  120.     typedef long double        floatParm;
  121.     typedef long double        doubleParm;
  122. #else
  123.     typedef    OSErr            OSErrParm;
  124.     typedef Boolean            BooleanParm;
  125.     typedef char            charParm;
  126.     typedef unsigned char    ucharParm;
  127.     typedef short            shortParm;
  128.     typedef unsigned short    ushortParm;
  129.     typedef float            floatParm;
  130.     typedef double            doubleParm;
  131. #endif
  132.  
  133. /*******************************************************************************
  134. ** Some external routines
  135. ********************************************************************************/
  136.  
  137. #ifndef FIX_ASLM
  138. #ifdef __cplusplus
  139. extern "C" {
  140. #endif
  141.     char* strcpy(char* s1, const char* s2);
  142. #ifdef __cplusplus
  143. }
  144. #endif
  145. #endif
  146.  
  147. /*******************************************************************************
  148. ** Error Constants
  149. ********************************************************************************/
  150.  
  151. #define kNoError                        0
  152. #define kASLMNotFoundErr                -3120
  153. #define kASLMNoParentErr                -3121
  154. #define kASLMParentNotFoundErr            -3122
  155. #define kASLMNotRelatedErr                -3123
  156. #define kASLMInvalidObjectErr            -3124
  157. #define kASLMPoolCorruptedErr            -3125
  158. #define kASLMOutOfMemoryErr                -3126
  159. #define kASLMCodeNotLoadedErr            -3127
  160. #define kASLMCouldNotLoadCodeErr        -3128
  161. #define kASLMFilePreflightedErr            -3129
  162. #define kASLMFileNotPreflightedErr        -3130
  163. #define kASLMFileNotFoundErr            -3131
  164. #define kASLMLibraryManagerNotLoadedErr    -3132
  165. #define kASLMDuplicateFoundErr            -3134
  166. #define kASLMSeedChangedErr                -3135
  167. #define kASLMUnconstructedObjectErr        -3136
  168. #define kASLMInternalErr                -3137
  169. #define kASLMVersionErr                    -3138
  170. #define kASLMFolderNotFoundErr            -3139
  171. #define kASLMFolderInUseErr                -3140
  172. #define kASLMResourceNotFoundErr        -3141
  173. #define kASLMInvalidSegmentNumberErr    -3142
  174. #define kASLMNotAllowedNowErr            -3155
  175. #define kASLMNotSupportedErr            -3167
  176.  
  177. /*******************************************************************************
  178. ** Typedefs
  179. ********************************************************************************/
  180.  
  181. //
  182. //    ASLM uses CDECLProcPtr instead of ProcPtr in all of its interfaces. It is the
  183. //    same as ProcPtr except when using SCpp. In this case it is declared as
  184. //    _cdecl so it will have C calling conventions instead of Cpp.
  185. //
  186. typedef long (* _CDECL CDECLProcPtr)();
  187.  
  188. typedef void*            GlobalWorld;
  189. #define kInvalidWorld    ((GlobalWorld)0)
  190.  
  191. typedef unsigned short    Version;
  192. typedef unsigned long    VersionParm;    // for passing a version as a paramter
  193. #define kAnyVersion        ((Version)0)
  194.  
  195. #define    TFunctionSetID    TClassID
  196. #define    TLibraryID        TClassID
  197.  
  198. #define    CastToFunctionSetID    CastToClassID    /* for casting a cstring to a TFunctionSetID */
  199. #define    CastToLibraryID        CastToClassID    /* for casting a cstring to a TLibraryID */
  200.  
  201. #define    FunctionSetID    CastToFunctionSetID    /* for casting a cstring to a TFunctionSetID */
  202. #define    LibraryID        CastToLibraryID        /* for casting a cstring to a TLibraryID */
  203. #ifndef ClassID        // make sure we don't conflict with MacApp
  204.     #define    ClassID        CastToClassID        /* for casting a cstring to a TLibraryID */
  205. #endif
  206.  
  207. /*******************************************************************************
  208. ** Forward class declarations
  209. ********************************************************************************/
  210.  
  211. #ifdef __cplusplus
  212.     class    TDynamic;
  213.     class    TLibraryManager;
  214.     class    TClassID;
  215.     class    TFunctionSetID;
  216.     class    TLibraryID;
  217.     class    TLibrary;
  218.     class    TFormattedStream;
  219.     class    TMemoryPool;
  220.     class    TStandardPool;
  221.     class    TLibraryFile;
  222.     class     TClassInfo;
  223.     class    TException;
  224.     class    TSimpleList;
  225.     class    TFileSpec;
  226. #else
  227.     typedef char* TClassID;
  228.     typedef void TDynamic;
  229.     typedef void TLibraryManager;
  230.     typedef void TFormattedStream;
  231.     typedef void TStandardPool;
  232.     typedef void TClassInfo;
  233.     typedef void TLibrary;
  234.     typedef void TMemoryPool;
  235. #endif
  236.  
  237.  
  238. /*******************************************************************************
  239. ** Memory definitions
  240. ********************************************************************************/
  241.  
  242. typedef int    ZoneType;
  243.  
  244. #define kSystemZone                ((ZoneType)1)
  245. #define kKernelZone                ((ZoneType)2)
  246. #define kApplicZone                ((ZoneType)3)
  247. #define kCurrentZone            ((ZoneType)4)
  248. #define kTempZone                ((ZoneType)5)
  249.  
  250. typedef int    MemoryType;
  251.  
  252. #define kNormalMemory            ((MemoryType)1)
  253. #define kHoldMemory                ((MemoryType)2)
  254. #define kLockMemory                ((MemoryType)3)
  255. #define kLockMemoryContiguous    ((MemoryType)4)
  256.  
  257. /*******************************************************************************
  258. ** ASLM Gestalt selector
  259. ********************************************************************************/
  260.  
  261. #define gestaltASLMPPC 'slmp'
  262. #define gestaltASLM68K 'aslm'
  263.  
  264. #if GENERATINGPOWERPC
  265.     #define gestaltASLM gestaltASLMPPC
  266. #else
  267.     #define gestaltASLM gestaltASLM68K
  268. #endif
  269.  
  270. /*
  271.     If the ASLM gestalt selector returns NULL then ASLM did not load properly
  272.     at boot time and is not available. Otherwise the version will be in the
  273.     upper 2 bytes of the result and lower 2 bits of the result will contain
  274.     information as described below.
  275. */
  276.  
  277. enum {
  278.     gestaltASLMVersionMask    = 0xffff0000,    /*    Version is in upper 2 bytes of result */
  279.     gestaltASLMPresentMask    = 0x0001,        /*    If first bit is set then ASLM was loaded
  280.                                                 at some point but may not be now. If you
  281.                                                 call InitLibraryManager, ASLM will load
  282.                                                 automatically, except at boot time, in
  283.                                                 which case it will set a flag so it stays
  284.                                                 loaded next time and then will reboot. */
  285.     gestaltASLMLoadedMask    = 0x0002        /*  If second bit is set then ASLM is
  286.                                                 currently loaded. */
  287. };
  288.  
  289. /*******************************************************************************
  290. ** Old interface definitions for backwards compatiblity.
  291. ********************************************************************************/
  292.  
  293. #ifndef SupportOldASLMInterfaces
  294. #define SupportOldASLMInterfaces 1
  295. #endif
  296.  
  297. #if SupportOldASLMInterfaces
  298.     //
  299.     // Old error code constants. New error code values are the same but the
  300.     // names were changed by adding "ASLM" to the front and "err" to the end.
  301.     //
  302.     #define kNotFound                        -3120
  303.     #define kNoParent                        -3121
  304.     #define kParentNotFound                    -3122
  305.     #define kNotRelated                        -3123
  306.     #define kInvalidObject                    -3124
  307.     #define kPoolCorrupted                    -3125
  308.     #define kOutOfMemory                    -3126
  309.     #define kCodeNotLoaded                    -3127
  310.     #define kCouldNotLoadCode                -3128
  311.     #define kFilePreflighted                -3129
  312.     #define kFileNotPreflighted                -3130
  313.     #define kFileNotFound                    -3131
  314.     #define kLibraryManagerNotLoaded        -3132
  315.     #define kDuplicateFound                    -3134
  316.     #define kSeedChanged                    -3135
  317.     #define kUnconstructedObject            -3136
  318.     #define kInternalError                    -3137
  319.     #define kVersionError                    -3138
  320.     #define kFolderNotFound                    -3139
  321.     #define kFolderInUse                    -3140
  322.     #define kResourceNotFound                -3141
  323.     #define kNotAllowedNow                    -3155
  324.     #define kNotSupported                    -3167
  325.  
  326.     //
  327.     //    The FSInfoGetParentID function was renamed to FSInfoGetInterfaceID
  328.     //
  329.     #define FSInfoGetParentID FSInfoGetInterfaceID
  330. #endif
  331.  
  332. /*******************************************************************************
  333. ** STACKOBJECTONLY: Use in a class declaration so the object can only be created
  334. ** on the stack. This makes the constructors and destructors much smaller since
  335. ** they know they will never have to new or delete memory.
  336. ********************************************************************************/
  337.  
  338. #define STACKOBJECTONLY                                                \
  339.     private:                                                        \
  340.                 void*    operator new(size_t) { return NULL; }        \
  341.                 void    operator delete(void*) {}
  342.  
  343. /*******************************************************************************
  344. ** Some "C" Global routines
  345. **
  346. ** InitLibraryManager initializes a client to use the ASLM. All clients
  347. ** must make this call except for ASLM libraries. CleanupLibraryManager
  348. ** should be called when the client is done using the ASLM.
  349. **
  350. ** GetLocalLibraryManager can be called after InitLibraryManager is called. If it
  351. ** returns NULL then InitLibraryManager failed.
  352. ********************************************************************************/
  353.  
  354. #ifdef __cplusplus
  355.     extern "C" {
  356. #endif
  357.  
  358. /*    -------------------------------------------------------------------------
  359.     These functions are for use by applications or stand-alone code 
  360.     resources only
  361.     ------------------------------------------------------------------------- */
  362.  
  363. #ifdef __cplusplus
  364.         
  365. OSErr                InitLibraryManager(size_t poolsize = 0, ZoneType = kCurrentZone,
  366.                                        MemoryType = kNormalMemory);
  367. void                CleanupLibraryManager();
  368.     
  369. #else
  370.  
  371. OSErr                InitLibraryManager(size_t poolsize, int zoneType, int memType);
  372. void                CleanupLibraryManager(void);
  373.     
  374. #endif
  375.  
  376. /*    -------------------------------------------------------------------------
  377.     Call FragmentIsNonApplicationASLMClient before calling InitLibraryManager
  378.     if you are writing a PowerPC CFM fragment that is not the main
  379.     application code fragment.
  380.     ------------------------------------------------------------------------- */
  381.  
  382. #if GENERATINGPOWERPC
  383.     void FragmentIsNonApplicationASLMClient();
  384. #endif
  385.  
  386.  
  387. /*    -------------------------------------------------------------------------
  388.     These functions can be used by any Shared Library Manager clients
  389.     ------------------------------------------------------------------------- */
  390.  
  391. #ifdef __cplusplus
  392.  
  393. Boolean                IsDerivedFrom(const void*, const TClassID&);
  394. const TClassID&        GetObjectsClassID(const void*);
  395. const TClassID&        GetObjectsParentClassID(const void*);
  396. unsigned short        GetObjectsVersion(const void*);
  397. unsigned short        GetObjectsMinVersion(const void*);
  398. size_t                GetObjectsSize(const void*);
  399. TLibrary*            GetObjectsLocalLibrary(const void*);
  400. TLibraryFile*        GetObjectsLocalLibraryFile(const void*);
  401. TStandardPool*        GetObjectsLocalPool(const void*);
  402. void                SetObjectsLocalPool(const void*, TStandardPool*);
  403.  
  404. void*                NewObject(const TClassID&, OSErr* = NULL,
  405.                               TMemoryPool* = NULL);
  406. void*                NewObjectWithParent(const TClassID&,
  407.                                         const TClassID& parentID,
  408.                                         OSErr* = NULL, TMemoryPool* = NULL);
  409. void*                NewObjectFromStream(const TFormattedStream&,
  410.                                         OSErr* = NULL, TMemoryPool* = NULL);
  411.  
  412. TClassInfo*         GetClassInfo(const TClassID&, OSErr* = NULL);
  413.  
  414. OSErr                VerifyClass(const TClassID&, const TClassID& parentID);
  415. void*                CastObject(const void*, const TClassID& parentID, OSErr* = NULL);
  416. void*                CastToMainObject(const void*);
  417.  
  418. OSErr                LoadClass(const TClassID&, BooleanParm forceAll);
  419. OSErr                UnloadClass(const TClassID&);
  420. Boolean                IsClassLoaded(const TClassID&);
  421.  
  422. OSErr                LoadFunctionSet(const TFunctionSetID&, BooleanParm forceAll);
  423. OSErr                UnloadFunctionSet(const TFunctionSetID&);
  424. Boolean                IsFunctionSetLoaded(const TFunctionSetID&);
  425.  
  426. CDECLProcPtr        GetFunctionPointer(const TFunctionSetID&, const char* funcName,
  427.                                        OSErr* = NULL);
  428. CDECLProcPtr        GetIndexedFunctionPointer(const TFunctionSetID&, unsigned int index,
  429.                                               OSErr* = NULL);
  430.  
  431. OSErr                LoadLibraries(BooleanParm forceAll = true,
  432.                                   BooleanParm doSelf = true);
  433. OSErr                UnloadLibraries();
  434. void                ResetFunctionSet(const TFunctionSetID* = NULL);
  435.         
  436. Boolean                TraceLogOn();
  437. Boolean                TraceLogOff();
  438.  
  439. void                RegisterDynamicObject(TDynamic*);
  440. void                UnregisterDynamicObject(TDynamic*);
  441.     
  442. TLibraryManager*    GetLocalLibraryManager();
  443.     
  444. TStandardPool*        GetLocalPool();
  445. void                SetLocalPool(TStandardPool*);
  446. TStandardPool*        GetClientPool();
  447. TStandardPool*        GetDefaultPool();
  448. void                SetDefaultPool(TStandardPool*);
  449. TStandardPool*        GetSystemPool();
  450.     
  451. #else
  452.     
  453. void*                NewObject(const TClassID, OSErr*, TStandardPool*);
  454. void*                NewObjectWithParent(const TClassID, const TClassID parentID,
  455.                                         OSErr*, TMemoryPool*);
  456. void*                NewObjectFromStream(const TFormattedStream*, OSErr*,
  457.                                         TMemoryPool*);
  458.  
  459. TClassInfo*         GetClassInfo(const TClassID, OSErr*);
  460.  
  461. OSErr                VerifyClass(const TClassID, const TClassID parentID);
  462. void*                CastObject(const void*, const TClassID parentID, OSErr*);
  463. void*                CastToMainObject(const void*);
  464.  
  465. OSErr                LoadClass(const TClassID, BooleanParm forceAll);
  466. OSErr                UnloadClass(const TClassID);
  467. Boolean                IsClassLoaded(const TClassID);
  468.  
  469. OSErr                LoadFunctionSet(const TFunctionSetID, BooleanParm forceAll);
  470. OSErr                UnloadFunctionSet(const TFunctionSetID);
  471. Boolean                IsFunctionSetLoaded(const TFunctionSetID);
  472.  
  473. ProcPtr                GetFunctionPointer(const TFunctionSetID, const char* funcName,
  474.                                        OSErr*);
  475. ProcPtr                GetIndexedFunctionPointer(const TFunctionSetID, unsigned int index,
  476.                                               OSErr*);
  477.  
  478. OSErr                LoadLibraries(BooleanParm forceAll, BooleanParm doSelf);
  479. OSErr                UnloadLibraries(void);
  480. void                ResetFunctionSet(const TFunctionSetID);
  481.         
  482. Boolean                TraceLogOn();
  483. Boolean                TraceLogOff();
  484.  
  485. TLibraryManager*    GetLocalLibraryManager(void);
  486.  
  487. TStandardPool*        GetLocalPool();
  488. void                SetLocalPool(TStandardPool*);
  489. TStandardPool*        GetClientPool();
  490. TStandardPool*        GetDefaultPool();
  491. void                SetDefaultPool(TStandardPool*);
  492. TStandardPool*        GetSystemPool();
  493.  
  494. #endif
  495.  
  496. /*
  497.     These routines are declared in LibraryManagerUtilities.h, but are needed
  498.     for the inlines below.
  499. */
  500.  
  501. void* SLMNewOperator(size_t, TMemoryPool*);
  502. void SLMDeleteOperator(void*);
  503.  
  504. #ifdef __cplusplus
  505. }
  506.  
  507.  
  508. /*******************************************************************************
  509. ** CLASS TSimpleDynamic
  510. **
  511. ** A base class for shared-library classes that has no virtual functions.  This
  512. ** class is NOT shared, since it is intended to be a trivial class that just
  513. ** forces the VTable to be at the front of the object.
  514. ********************************************************************************/
  515.  
  516. #if SINGLEOBJECT
  517. class TSimpleDynamic : public SingleObject
  518. #else
  519. class TSimpleDynamic
  520. #endif
  521. {
  522.     ASLM_COMPATIBLE
  523.  
  524.     public:
  525.         virtual                  ~ _CDECL TSimpleDynamic();
  526.         
  527.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  528.                                     { return SLMNewOperator(size, pool); }
  529.                 void*            operator new(size_t size)                        // from default pool
  530.                                     { return SLMNewOperator(size, 0); }
  531.                 void            operator delete(void* obj, size_t)
  532.                                     { SLMDeleteOperator(obj); }
  533.  
  534.                 const TClassID&    GetObjectsClassID() const;
  535.                 const TClassID&    GetObjectsParentClassID() const;
  536.                 unsigned short    GetObjectsVersion() const;
  537.                 unsigned short    GetObjectsMinVersion() const;
  538.                 size_t            GetObjectsSize() const;
  539.                 TLibrary*        GetObjectsLocalLibrary() const;
  540.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  541.                 TStandardPool*    GetObjectsLocalPool() const;
  542.                 void            SetObjectsLocalPool(TStandardPool*) const;
  543.     
  544.                 Boolean            IsDerivedFrom(const TClassID&) const;
  545.                 
  546.     protected:
  547.                                   _CDECL TSimpleDynamic();
  548.  
  549.     private:
  550.                                 TSimpleDynamic(const TSimpleDynamic&);
  551.                 void            operator=(const TSimpleDynamic&);
  552. };
  553.  
  554. /*******************************************************************************
  555. ** CLASS TDynamic
  556. **
  557. ** The base class for shared-library classes with a set of common capabilities.
  558. ** This class provides the same capabilities as TStdDynamic.
  559. ********************************************************************************/
  560.  
  561. typedef int    TraceControlType;
  562.  
  563. #define kTraceStatus    ((TraceControlType)1)
  564. #define kTraceOn        ((TraceControlType)2)
  565. #define kTraceOff        ((TraceControlType)3)
  566.  
  567. #define kTDynamicID "!$dyna,1.2"
  568.  
  569. #if SINGLEOBJECT
  570. class TDynamic : public SingleObject
  571. #else
  572. class TDynamic
  573. #endif
  574. {
  575.     ASLM_COMPATIBLE
  576.  
  577.     public:
  578.         virtual                  ~ _CDECL TDynamic();
  579.         
  580.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  581.                                     { return SLMNewOperator(size, pool); }
  582.                 void*            operator new(size_t size)                        // from default pool
  583.                                     { return SLMNewOperator(size, 0); }
  584.                 void            operator delete(void* obj, size_t)
  585.                                     { SLMDeleteOperator(obj); }
  586.                                     
  587.  
  588.         const TClassID&            GetObjectsClassID() const;
  589.         const TClassID&            GetObjectsParentClassID() const;
  590.                 unsigned short    GetObjectsVersion() const;
  591.                 unsigned short    GetObjectsMinVersion() const;
  592.                 size_t            GetObjectsSize() const;
  593.                 TLibrary*        GetObjectsLocalLibrary() const;
  594.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  595.                 TStandardPool*    GetObjectsLocalPool() const;
  596.                 void            SetObjectsLocalPool(TStandardPool*) const;
  597.  
  598.         virtual Boolean            _CDECL IsValid() const;
  599.         
  600.         virtual    OSErr            _CDECL Inflate(TFormattedStream&);
  601.         virtual OSErr            _CDECL Flatten(TFormattedStream&) const;
  602.         virtual TDynamic*        _CDECL Clone(TStandardPool*) const;
  603.         
  604.         virtual    char*            _CDECL GetVerboseName(char*) const;
  605.         virtual    void            _CDECL Dump() const;
  606.         
  607.                 void            _CDECL Trace(char *formatStr, ...) const;
  608.         virtual    Boolean            _CDECL TraceControl(TraceControlType) const;
  609.                 Boolean            IsTraceOn() const;    
  610.                 Boolean            TraceOn() const;
  611.                 Boolean            TraceOff() const;
  612.     
  613.                 Boolean            IsDerivedFrom(const TClassID&) const;
  614.                 
  615.     protected:
  616.                                   _CDECL TDynamic();
  617.  
  618.     private:
  619.                                 TDynamic(const TDynamic&);
  620.                 void            operator=(const TDynamic&);
  621. };
  622.  
  623. /*    -------------------------------------------------------------------------
  624.     Inline methods for TDynamic
  625.     ------------------------------------------------------------------------- */
  626.  
  627.     inline Boolean TDynamic::IsTraceOn() const
  628.     {
  629.         return TraceControl(kTraceStatus);
  630.     }
  631.  
  632.     inline Boolean TDynamic::TraceOn() const
  633.     {
  634.         return TraceControl(kTraceOn);
  635.     }
  636.  
  637.     inline Boolean TDynamic::TraceOff() const
  638.     {
  639.         return TraceControl(kTraceOff);
  640.     }
  641.  
  642. /*******************************************************************************
  643. ** CLASS MDynamic
  644. **
  645. ** A base class for shared-library classes, which has one 1 virtual function (the
  646. ** destructor).  This class is NOT shared, since it is intended to be a trivial class
  647. ** that can be used to force the VTable to be at the front of the object for
  648. ** mixin classes.
  649. ********************************************************************************/
  650.  
  651. class MDynamic
  652. {
  653.     ASLM_COMPATIBLE
  654.  
  655.     public:
  656.         virtual                  ~_CDECL MDynamic();
  657.         
  658.     protected:
  659.                                   _CDECL MDynamic();
  660.  
  661.     private:
  662.                                 MDynamic(const MDynamic&);
  663.                 void            operator=(const MDynamic&);
  664. };
  665.  
  666. /*******************************************************************************
  667. ** CLASS TStdDynamic
  668. **
  669. ** The base class for shared-library classes with a set of common capabilities.
  670. ** This class provides the same capabilities as TDynamic below, but is for
  671. ** classes that you don't want to descend from SingleObject.
  672. ********************************************************************************/
  673.  
  674. #define kTStdDynamicID "!$sdyn,1.2"
  675.  
  676. class TStdDynamic
  677. {
  678.     ASLM_COMPATIBLE
  679.  
  680.     public:
  681.         virtual                  ~ _CDECL TStdDynamic();
  682.         
  683.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  684.                                     { return SLMNewOperator(size, pool); }
  685.                 void*            operator new(size_t size)                        // from default pool
  686.                                     { return SLMNewOperator(size, 0); }
  687.                 void            operator delete(void* obj, size_t)
  688.                                     { SLMDeleteOperator(obj); }
  689.                                     
  690.  
  691.         const TClassID&            GetObjectsClassID() const;
  692.                 unsigned short    GetObjectsVersion() const;
  693.                 unsigned short    GetObjectsMinVersion() const;
  694.                 size_t            GetObjectsSize() const;
  695.                 TLibrary*        GetObjectsLocalLibrary() const;
  696.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  697.                 TStandardPool*    GetObjectsLocalPool() const;
  698.                 void            SetObjectsLocalPool(TStandardPool*) const;
  699.  
  700.         virtual Boolean            _CDECL IsValid() const;
  701.         
  702.         virtual    OSErr            _CDECL Inflate(TFormattedStream&);
  703.         virtual OSErr            _CDECL Flatten(TFormattedStream&) const;
  704.         virtual TDynamic*        _CDECL Clone(TStandardPool*) const;
  705.         
  706.         virtual    char*            _CDECL GetVerboseName(char*) const;
  707.         virtual    void            _CDECL Dump() const;
  708.         
  709.                 void            _CDECL Trace(char *formatStr, ...) const;
  710.         virtual    Boolean            _CDECL TraceControl(TraceControlType) const;
  711.                 Boolean            IsTraceOn() const;    
  712.                 Boolean            TraceOn() const;
  713.                 Boolean            TraceOff() const;
  714.     
  715.                 Boolean            IsDerivedFrom(const TClassID&) const;
  716.                 
  717.     protected:
  718.                                   _CDECL TStdDynamic();
  719.  
  720.     private:
  721.                                 TStdDynamic(const TDynamic&);
  722.                 void            operator=(const TDynamic&);
  723. };
  724.  
  725. /*    -------------------------------------------------------------------------
  726.     Inline methods for TStdDynamic
  727.     ------------------------------------------------------------------------- */
  728.     
  729.     inline Boolean TStdDynamic::IsTraceOn() const
  730.     {
  731.         return TraceControl(kTraceStatus);
  732.     }
  733.  
  734.     inline Boolean TStdDynamic::TraceOn() const
  735.     {
  736.         return TraceControl(kTraceOn);
  737.     }
  738.  
  739.     inline Boolean TStdDynamic::TraceOff() const
  740.     {
  741.         return TraceControl(kTraceOff);
  742.     }
  743.  
  744. /*******************************************************************************
  745. ** CLASS TStdSimpleDynamic
  746. **
  747. ** A base class for shared-library classes that has no virtual functions.  This
  748. ** class is NOT shared, since it is intended to be a trivial class that just
  749. ** forces the VTable to be at the front of the object.
  750. ********************************************************************************/
  751.  
  752. class TStdSimpleDynamic
  753. {
  754.     ASLM_COMPATIBLE
  755.  
  756.     public:
  757.         virtual                  ~ _CDECL TStdSimpleDynamic();
  758.         
  759.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  760.                                     { return SLMNewOperator(size, pool); }
  761.                 void*            operator new(size_t size)                        // from default pool
  762.                                     { return SLMNewOperator(size, 0); }
  763.                 void            operator delete(void* obj, size_t)
  764.                                     { SLMDeleteOperator(obj); }
  765.  
  766.                 const TClassID&    GetObjectsClassID() const;
  767.                 unsigned short    GetObjectsVersion() const;
  768.                 unsigned short    GetObjectsMinVersion() const;
  769.                 size_t            GetObjectsSize() const;
  770.                 TLibrary*        GetObjectsLocalLibrary() const;
  771.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  772.                 TStandardPool*    GetObjectsLocalPool() const;
  773.                 void            SetObjectsLocalPool(TStandardPool*) const;
  774.     
  775.                 Boolean            IsDerivedFrom(const TClassID&) const;
  776.                 
  777.     protected:
  778.                                   _CDECL TStdSimpleDynamic();
  779.  
  780.     private:
  781.                                 TStdSimpleDynamic(const TStdSimpleDynamic&);
  782.                 void            operator=(const TStdSimpleDynamic&);
  783. };
  784.  
  785. #if defined(__SC__) || defined(__MRC__)
  786.  
  787. /*******************************************************************************
  788. ** CLASS TSCSimpleDynamic
  789. **
  790. ** A base class for shared-library classes that has no virtual functions.  This
  791. ** class is NOT shared, since it is intended to be a trivial class that just
  792. ** forces the VTable to be at the front of the object, and override new to
  793. ** use the ASLM operators. It is used as a simple base class for Symantec C++ objects.
  794. ** This is the normal subclass for Symantec C++ objects that are not going to 
  795. ** intermix with MPW C++ objects.
  796. ********************************************************************************/
  797.  
  798. class TSCSimpleDynamic
  799. {
  800.     ASLM_COMPATIBLE
  801.  
  802.     public:
  803.         virtual                  ~TSCSimpleDynamic();
  804.         
  805.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  806.                                     { return SLMNewOperator(size, pool); }
  807.                 void*            operator new(size_t size)                        // from default pool
  808.                                     { return SLMNewOperator(size, 0); }
  809.                 void            operator delete(void* obj, size_t)
  810.                                     { SLMDeleteOperator(obj); }
  811.  
  812.                 const TClassID&    GetObjectsClassID() const;
  813.                 const TClassID&    GetObjectsParentClassID() const;
  814.                 unsigned short    GetObjectsVersion() const;
  815.                 unsigned short    GetObjectsMinVersion() const;
  816.                 size_t            GetObjectsSize() const;
  817.                 TLibrary*        GetObjectsLocalLibrary() const;
  818.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  819.                 TStandardPool*    GetObjectsLocalPool() const;
  820.                 void            SetObjectsLocalPool(TStandardPool*) const;
  821.     
  822.                 Boolean            IsDerivedFrom(const TClassID&) const;
  823.                 
  824.     protected:
  825.                                   TSCSimpleDynamic();
  826.  
  827.     private:
  828.                                 TSCSimpleDynamic(const TSCSimpleDynamic&);
  829.                 void            operator=(const TSCSimpleDynamic&);
  830. };
  831.  
  832. /*******************************************************************************
  833. ** CLASS TSCDynamic
  834. **
  835. ** The base class for shared-library classes with a set of common capabilities.
  836. ** This class provides the same capabilities as TStdDynamic.  It is only for
  837. ** Symantec C++ implementations
  838. ********************************************************************************/
  839.  
  840. #define kTSCDynamicID "!$scdy,1.2"
  841.  
  842. class TSCDynamic
  843. {
  844.     ASLM_COMPATIBLE
  845.  
  846.     public:
  847.         virtual                  ~ _cdecl TSCDynamic();
  848.         
  849.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  850.                                     { return SLMNewOperator(size, pool); }
  851.                 void*            operator new(size_t size)                        // from default pool
  852.                                     { return SLMNewOperator(size, 0); }
  853.                 void            operator delete(void* obj, size_t)
  854.                                     { SLMDeleteOperator(obj); }
  855.  
  856.         const TClassID&            GetObjectsClassID() const;
  857.         const TClassID&            GetObjectsParentClassID() const;
  858.                 unsigned short    GetObjectsVersion() const;
  859.                 unsigned short    GetObjectsMinVersion() const;
  860.                 size_t            GetObjectsSize() const;
  861.                 TLibrary*        GetObjectsLocalLibrary() const;
  862.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  863.                 TStandardPool*    GetObjectsLocalPool() const;
  864.                 void            SetObjectsLocalPool(TStandardPool*) const;
  865.  
  866.         virtual Boolean            _cdecl IsValid() const;
  867.         
  868.         virtual    OSErr            _cdecl Inflate(TFormattedStream&);
  869.         virtual OSErr            _cdecl Flatten(TFormattedStream&) const;
  870.         virtual TSCDynamic*        _cdecl Clone(TStandardPool*) const;
  871.         
  872.         virtual    char*            _cdecl GetVerboseName(char*) const;
  873.         virtual    void            _cdecl Dump() const;
  874.         
  875.                 void            _cdecl Trace(char *formatStr, ...) const;
  876.         virtual    Boolean            _cdecl TraceControl(TraceControlType) const;
  877.                 Boolean            IsTraceOn() const;    
  878.                 Boolean            TraceOn() const;
  879.                 Boolean            TraceOff() const;
  880.     
  881.                 Boolean            IsDerivedFrom(const TClassID&) const;
  882.                 
  883.     protected:
  884.                                   _cdecl TSCDynamic();
  885.  
  886.     private:
  887.                                 TSCDynamic(const TSCDynamic&);
  888.                 void            operator=(const TSCDynamic&);
  889. };
  890.  
  891. /*    -------------------------------------------------------------------------
  892.     Inline methods for TSCDynamic
  893.     ------------------------------------------------------------------------- */
  894.  
  895.     inline Boolean TSCDynamic::IsTraceOn() const
  896.     {
  897.         return TraceControl(kTraceStatus);
  898.     }
  899.  
  900.     inline Boolean TSCDynamic::TraceOn() const
  901.     {
  902.         return TraceControl(kTraceOn);
  903.     }
  904.  
  905.     inline Boolean TSCDynamic::TraceOff() const
  906.     {
  907.         return TraceControl(kTraceOff);
  908.     }
  909.     
  910. #endif    /* __SC__ */
  911. #endif    /* __cplusplus */
  912.  
  913. /*******************************************************************************
  914. ** Class TClassID, TFunctionSetID, and TLibraryID
  915. **
  916. ** TFunctionSetID and TLibraryID are typedef'd to be the same as TClassID
  917. ********************************************************************************/
  918.  
  919. #define kMaxClassIDSize        255
  920.  
  921. #ifdef __cplusplus
  922.  
  923. const TClassID& CastToClassID(const char* str);    // cast a char* to a TClassID
  924.  
  925. Boolean operator==(const TClassID&, const char *);
  926. Boolean operator!=(const TClassID&, const char *);
  927. Boolean operator==(const char *, const TClassID&);
  928. Boolean operator!=(const char *, const TClassID&);
  929.  
  930. class TClassID
  931. {
  932.     public:
  933.         void*        operator new(size_t, size_t strLen, TMemoryPool* thePool = NULL)
  934.                     {
  935.                         return SLMNewOperator(strLen+1, thePool);
  936.                     }
  937.  
  938.         void*        operator new(size_t)
  939.                     {
  940.                         return SLMNewOperator(kMaxClassIDSize+1, NULL);
  941.                     }
  942.                         
  943.         void        operator delete(void* obj, size_t)
  944.                         { SLMDeleteOperator(obj); }
  945.  
  946.                     TClassID();
  947.                     TClassID(const TClassID&);
  948.  
  949.                     operator const char*() const;        // cast to a const char *
  950.  
  951.         Version        _CDECL ExtractVersion() const;
  952.         size_t        _CDECL GetLength() const;
  953.         
  954.         TClassID&    operator=(const TClassID&);
  955.  
  956.         Boolean        _CDECL operator==(const TClassID&) const;
  957.         Boolean        operator!=(const TClassID&) const;
  958.  
  959.     private:
  960.         char                fClassIDStr[kMaxClassIDSize + 1];
  961. };
  962.  
  963. /*    -------------------------------------------------------------------------
  964.     Inline methods for TClassID
  965.     ------------------------------------------------------------------------- */
  966.  
  967.     //
  968.     // constructors
  969.     //
  970.  
  971.     inline TClassID::TClassID()
  972.     {
  973.         fClassIDStr[0] = 0;
  974.     }
  975.     
  976.     inline TClassID::TClassID(const TClassID& classID)
  977.     {
  978.         strcpy(fClassIDStr, classID.fClassIDStr);
  979.     }
  980.  
  981.     //
  982.     // cast operators
  983.     //
  984.  
  985.     inline const TClassID& CastToClassID(const char* str)
  986.     {
  987.         return *(const TClassID*)str;
  988.     }
  989.     
  990.     inline TClassID::operator const char *() const
  991.     {
  992.         return fClassIDStr;
  993.     }
  994.  
  995.     //
  996.     // compare operators
  997.     //
  998.     
  999.     inline Boolean TClassID::operator!=(const TClassID& classID) const
  1000.     {
  1001.         return !(*this == classID);
  1002.     }
  1003.     
  1004.     inline Boolean operator!=(const TClassID& id1, const char *id2)
  1005.     {
  1006.         return !(id1 == CastToClassID(id2));
  1007.     }
  1008.  
  1009.     inline Boolean operator!=(const char *id1, const TClassID& id2)
  1010.     {
  1011.         return !(id2 == CastToClassID(id1));
  1012.     }
  1013.     
  1014.     inline Boolean operator==(const TClassID& id1, const char *id2)
  1015.     {
  1016.         return (id1 == CastToClassID(id2));
  1017.     }
  1018.     
  1019.     inline Boolean operator==(const char *id1, const TClassID& id2)
  1020.     {
  1021.         return (id2 == CastToClassID(id1));
  1022.     }
  1023.  
  1024.     //
  1025.     // assignment operators
  1026.     //
  1027.     
  1028.     inline TClassID& TClassID::operator=(const TClassID& classID)
  1029.     {
  1030.         strcpy(fClassIDStr, classID.fClassIDStr);
  1031.         return *this;
  1032.     }
  1033.     
  1034. #endif
  1035.  
  1036. /*******************************************************************************
  1037. ** Class TLibraryManager
  1038. **
  1039. ** The user's interface to the world! 
  1040. ********************************************************************************/
  1041.  
  1042. #ifdef __cplusplus
  1043.  
  1044. #define kTLibraryManagerID "!$lmgr,1.2"
  1045.  
  1046. class TLibraryManager : public TDynamic 
  1047. {
  1048.  
  1049.     private:
  1050.         virtual                    ~ _CDECL TLibraryManager();
  1051.                                 _CDECL TLibraryManager(TStandardPool* = NULL, TLibraryFile* = NULL);
  1052.  
  1053.     public:
  1054.         virtual    void            _CDECL Dump() const;
  1055.  
  1056.         // New Methods
  1057.         
  1058.         virtual    void*            _CDECL NewObject(const TClassID& classID,
  1059.                                     OSErr* = NULL, TMemoryPool* = NULL) const;
  1060.         virtual    void*            _CDECL NewObject(const TClassID& classID, const TClassID& baseClassID,
  1061.                                     OSErr* = NULL, TMemoryPool* = NULL) const;
  1062.         virtual    void*            _CDECL NewObject(const TFormattedStream&,
  1063.                                     OSErr* = NULL, TMemoryPool* = NULL) const;
  1064.  
  1065.         virtual TClassInfo*     _CDECL GetClassInfo(const TClassID&, OSErr* = NULL) const;
  1066.  
  1067.         virtual OSErr            _CDECL VerifyClass(const TClassID& classID, const TClassID& baseClassID) const;
  1068.         virtual void*            _CDECL CastObject(const void* obj, const TClassID& parentID,
  1069.                                                 OSErr* = NULL) const;
  1070.         virtual void*            _CDECL CastToMainObject(const void* obj) const;
  1071.         
  1072.         virtual OSErr            _CDECL LoadClass(const TClassID&, BooleanParm loadAll = false);
  1073.         virtual OSErr            _CDECL UnloadClass(const TClassID&);
  1074.         virtual Boolean            _CDECL IsClassLoaded(const TClassID&) const;
  1075.  
  1076.                 OSErr            LoadFunctionSet(const TFunctionSetID&, BooleanParm loadAll = false);
  1077.                 OSErr            UnloadFunctionSet(const TFunctionSetID&);
  1078.                 Boolean            IsFunctionSetLoaded(const TFunctionSetID&) const;
  1079.         
  1080.         virtual CDECLProcPtr    _CDECL GetFunctionPointer(const TFunctionSetID&,
  1081.                                                    const char* funcName,
  1082.                                                    OSErr* = NULL);
  1083.         virtual CDECLProcPtr    _CDECL GetFunctionPointer(const TFunctionSetID&,
  1084.                                                    unsigned int index,
  1085.                                                    OSErr* = NULL);
  1086.         
  1087.         virtual OSErr            _CDECL LoadLibraries(BooleanParm forceAll = true,
  1088.                                                    BooleanParm doSelf = true);
  1089.         virtual OSErr            _CDECL UnloadLibraries();
  1090.         virtual void            _CDECL ResetFunctionSet(const TFunctionSetID* = NULL);
  1091.         
  1092.         virtual Boolean            _CDECL TraceLogOn();
  1093.         virtual Boolean            _CDECL TraceLogOff();
  1094.         
  1095.         virtual    void            _CDECL RegisterDynamicObject(TDynamic*);
  1096.         virtual    void            _CDECL UnregisterDynamicObject(TDynamic*);
  1097.  
  1098.                 void            SetObjectPool(TStandardPool*);
  1099.                 TStandardPool*    GetObjectPool() const;
  1100.                 void            SetDefaultPool(TStandardPool*);
  1101.                 TStandardPool*    GetDefaultPool() const;
  1102.                 GlobalWorld        _CDECL GetGlobalWorld() const;
  1103.         virtual    TLibrary*        _CDECL GetLibrary() const;
  1104.         virtual    TLibraryFile*    _CDECL GetLibraryFile() const;
  1105.  
  1106.     private:
  1107.                                 TLibraryManager(const TLibraryManager&);
  1108.                 void            operator=(const TLibraryManager&);
  1109.     private:        
  1110.         TStandardPool*            fPool;            // pool used for new objects and local pool
  1111.         TLibraryFile*            fLibraryFile;
  1112.         TStandardPool*            fDefaultPool;
  1113.         GlobalWorld                fGlobalWorld;
  1114.  
  1115. };
  1116.  
  1117. /*    -------------------------------------------------------------------------
  1118.     Inline Methods for TLibraryManager
  1119.     ------------------------------------------------------------------------- */
  1120.     
  1121.     inline OSErr TLibraryManager::LoadFunctionSet(const TFunctionSetID& functionSetID, BooleanParm loadAll)
  1122.     {
  1123.         return LoadClass(functionSetID, loadAll);
  1124.     }
  1125.     
  1126.     inline OSErr TLibraryManager::UnloadFunctionSet(const TFunctionSetID& functionSetID)
  1127.     {
  1128.         return UnloadClass(functionSetID);
  1129.     }
  1130.     
  1131.     inline Boolean TLibraryManager::IsFunctionSetLoaded(const TFunctionSetID& functionSetID) const
  1132.     {
  1133.         return IsClassLoaded(functionSetID);
  1134.     }
  1135.     
  1136.     inline TStandardPool* TLibraryManager::GetObjectPool() const
  1137.     {
  1138.         return fPool;
  1139.     }
  1140.     
  1141.     inline void TLibraryManager::SetObjectPool(TStandardPool* thePool)
  1142.     {
  1143.         fPool = thePool;
  1144.     }
  1145.         
  1146.     inline TStandardPool* TLibraryManager::GetDefaultPool() const
  1147.     {
  1148.         return fDefaultPool;
  1149.     }
  1150.  
  1151.     inline void TLibraryManager::SetDefaultPool(TStandardPool* thePool)
  1152.     {
  1153.         fDefaultPool = thePool;
  1154.     }
  1155.     
  1156.     inline GlobalWorld TLibraryManager::GetGlobalWorld() const
  1157.     {
  1158.         return fGlobalWorld;
  1159.     }
  1160.  
  1161. /*    -------------------------------------------------------------------------
  1162.     Inline for IsDerivedFrom
  1163.     ------------------------------------------------------------------------- */
  1164.  
  1165.     inline Boolean IsDerivedFrom(const void* obj, const TClassID& id)
  1166.     {
  1167.         return (GetLocalLibraryManager()->CastObject(obj, id) != NULL);
  1168.     }
  1169.  
  1170. /*    -------------------------------------------------------------------------
  1171.     Inline methods for TDynamic
  1172.     ------------------------------------------------------------------------- */
  1173.  
  1174.     inline Boolean TDynamic::IsDerivedFrom(const TClassID& id) const
  1175.     {
  1176.         return ::IsDerivedFrom(this, id);
  1177.     }
  1178.  
  1179.     inline const TClassID& TDynamic::GetObjectsClassID() const
  1180.     {
  1181.         return ::GetObjectsClassID(this);
  1182.     }
  1183.  
  1184.     inline const TClassID& TDynamic::GetObjectsParentClassID() const
  1185.     {
  1186.         return ::GetObjectsParentClassID(this);
  1187.     }
  1188.  
  1189.     inline unsigned short TDynamic::GetObjectsVersion() const
  1190.     {
  1191.         return ::GetObjectsVersion(this);
  1192.     }
  1193.  
  1194.     inline unsigned short TDynamic::GetObjectsMinVersion() const
  1195.     {
  1196.         return ::GetObjectsMinVersion(this);
  1197.     }
  1198.  
  1199.     inline size_t TDynamic::GetObjectsSize() const
  1200.     {
  1201.         return ::GetObjectsSize(this);
  1202.     }
  1203.  
  1204.     inline TLibrary* TDynamic::GetObjectsLocalLibrary() const
  1205.     {
  1206.         return ::GetObjectsLocalLibrary(this);
  1207.     }
  1208.  
  1209.     inline TLibraryFile* TDynamic::GetObjectsLocalLibraryFile() const
  1210.     {
  1211.         return ::GetObjectsLocalLibraryFile(this);
  1212.     }
  1213.  
  1214.     inline TStandardPool* TDynamic::GetObjectsLocalPool() const
  1215.     {
  1216.         return ::GetObjectsLocalPool(this);
  1217.     }
  1218.  
  1219.     inline void TDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1220.     {
  1221.         ::SetObjectsLocalPool(this, pool);
  1222.     }
  1223.     
  1224. /*    -------------------------------------------------------------------------
  1225.     Inline methods for TSimpleDynamic
  1226.     ------------------------------------------------------------------------- */
  1227.  
  1228.     inline const TClassID& TSimpleDynamic::GetObjectsClassID() const
  1229.     {
  1230.         return ((const TDynamic*)this)->GetObjectsClassID();
  1231.     }
  1232.  
  1233.     inline const TClassID& TSimpleDynamic::GetObjectsParentClassID() const
  1234.     {
  1235.         return ((const TDynamic*)this)->GetObjectsParentClassID();
  1236.     }
  1237.  
  1238.     inline unsigned short TSimpleDynamic::GetObjectsVersion() const
  1239.     {
  1240.         return ::GetObjectsVersion(this);
  1241.     }
  1242.  
  1243.     inline unsigned short TSimpleDynamic::GetObjectsMinVersion() const
  1244.     {
  1245.         return ::GetObjectsMinVersion(this);
  1246.     }
  1247.  
  1248.     inline size_t TSimpleDynamic::GetObjectsSize() const
  1249.     {
  1250.         return ((const TDynamic*)this)->GetObjectsSize();
  1251.     }
  1252.  
  1253.     inline TLibrary* TSimpleDynamic::GetObjectsLocalLibrary() const
  1254.     {
  1255.         return ((const TDynamic*)this)->GetObjectsLocalLibrary();
  1256.     }
  1257.  
  1258.     inline TLibraryFile* TSimpleDynamic::GetObjectsLocalLibraryFile() const
  1259.     {
  1260.         return ((const TDynamic*)this)->GetObjectsLocalLibraryFile();
  1261.     }
  1262.  
  1263.     inline TStandardPool* TSimpleDynamic::GetObjectsLocalPool() const
  1264.     {
  1265.         return ((const TDynamic*)this)->GetObjectsLocalPool();
  1266.     }
  1267.  
  1268.     inline void TSimpleDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1269.     {
  1270.         ((const TDynamic*)this)->SetObjectsLocalPool(pool);
  1271.     }
  1272.  
  1273.     inline Boolean TSimpleDynamic::IsDerivedFrom(const TClassID& id) const
  1274.     {
  1275.         return ((const TDynamic*)this)->IsDerivedFrom(id);
  1276.     }
  1277.     
  1278. /*    -------------------------------------------------------------------------
  1279.     Inline methods for TStdDynamic
  1280.     ------------------------------------------------------------------------- */
  1281.  
  1282.     inline const TClassID& TStdDynamic::GetObjectsClassID() const
  1283.     {
  1284.         return ((const TDynamic*)this)->GetObjectsClassID();
  1285.     }
  1286.  
  1287.     inline unsigned short TStdDynamic::GetObjectsVersion() const
  1288.     {
  1289.         return ::GetObjectsVersion(this);
  1290.     }
  1291.  
  1292.     inline unsigned short TStdDynamic::GetObjectsMinVersion() const
  1293.     {
  1294.         return ::GetObjectsMinVersion(this);
  1295.     }
  1296.  
  1297.     inline size_t TStdDynamic::GetObjectsSize() const
  1298.     {
  1299.         return ((const TDynamic*)this)->GetObjectsSize();
  1300.     }
  1301.  
  1302.     inline TLibrary* TStdDynamic::GetObjectsLocalLibrary() const
  1303.     {
  1304.         return ((const TDynamic*)this)->GetObjectsLocalLibrary();
  1305.     }
  1306.  
  1307.     inline TLibraryFile* TStdDynamic::GetObjectsLocalLibraryFile() const
  1308.     {
  1309.         return ((const TDynamic*)this)->GetObjectsLocalLibraryFile();
  1310.     }
  1311.  
  1312.     inline TStandardPool* TStdDynamic::GetObjectsLocalPool() const
  1313.     {
  1314.         return ((const TDynamic*)this)->GetObjectsLocalPool();
  1315.     }
  1316.  
  1317.     inline void TStdDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1318.     {
  1319.         ((const TDynamic*)this)->SetObjectsLocalPool(pool);
  1320.     }
  1321.     
  1322.     inline Boolean TStdDynamic::IsDerivedFrom(const TClassID& id) const
  1323.     {
  1324.         return ((const TDynamic*)this)->IsDerivedFrom(id);
  1325.     }
  1326.  
  1327. /*    -------------------------------------------------------------------------
  1328.     Inline methods for TStdSimpleDynamic
  1329.     ------------------------------------------------------------------------- */
  1330.  
  1331.     inline const TClassID& TStdSimpleDynamic::GetObjectsClassID() const
  1332.     {
  1333.         return ((const TDynamic*)this)->GetObjectsClassID();
  1334.     }
  1335.  
  1336.     inline unsigned short TStdSimpleDynamic::GetObjectsVersion() const
  1337.     {
  1338.         return ::GetObjectsVersion(this);
  1339.     }
  1340.  
  1341.     inline unsigned short TStdSimpleDynamic::GetObjectsMinVersion() const
  1342.     {
  1343.         return ::GetObjectsMinVersion(this);
  1344.     }
  1345.  
  1346.     inline size_t TStdSimpleDynamic::GetObjectsSize() const
  1347.     {
  1348.         return ((const TDynamic*)this)->GetObjectsSize();
  1349.     }
  1350.  
  1351.     inline TLibrary* TStdSimpleDynamic::GetObjectsLocalLibrary() const
  1352.     {
  1353.         return ((const TDynamic*)this)->GetObjectsLocalLibrary();
  1354.     }
  1355.  
  1356.     inline TLibraryFile* TStdSimpleDynamic::GetObjectsLocalLibraryFile() const
  1357.     {
  1358.         return ((const TDynamic*)this)->GetObjectsLocalLibraryFile();
  1359.     }
  1360.  
  1361.     inline TStandardPool* TStdSimpleDynamic::GetObjectsLocalPool() const
  1362.     {
  1363.         return ((const TDynamic*)this)->GetObjectsLocalPool();
  1364.     }
  1365.  
  1366.     inline void TStdSimpleDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1367.     {
  1368.         ((const TDynamic*)this)->SetObjectsLocalPool(pool);
  1369.     }
  1370.     
  1371.     inline Boolean TStdSimpleDynamic::IsDerivedFrom(const TClassID& id) const
  1372.     {
  1373.         return ((const TDynamic*)this)->IsDerivedFrom(id);
  1374.     }
  1375.     
  1376. #if defined(__SC__) || defined(__MRC__)
  1377.  
  1378. /*    -------------------------------------------------------------------------
  1379.     Inline methods for TSCDynamic
  1380.     ------------------------------------------------------------------------- */
  1381.  
  1382.     inline Boolean TSCDynamic::IsDerivedFrom(const TClassID& id) const
  1383.     {
  1384.         return ::IsDerivedFrom(this, id);
  1385.     }
  1386.  
  1387.     inline const TClassID& TSCDynamic::GetObjectsClassID() const
  1388.     {
  1389.         return ::GetObjectsClassID(this);
  1390.     }
  1391.  
  1392.     inline const TClassID& TSCDynamic::GetObjectsParentClassID() const
  1393.     {
  1394.         return ::GetObjectsParentClassID(this);
  1395.     }
  1396.  
  1397.     inline unsigned short TSCDynamic::GetObjectsVersion() const
  1398.     {
  1399.         return ::GetObjectsVersion(this);
  1400.     }
  1401.  
  1402.     inline unsigned short TSCDynamic::GetObjectsMinVersion() const
  1403.     {
  1404.         return ::GetObjectsMinVersion(this);
  1405.     }
  1406.  
  1407.     inline size_t TSCDynamic::GetObjectsSize() const
  1408.     {
  1409.         return ::GetObjectsSize(this);
  1410.     }
  1411.  
  1412.     inline TLibrary* TSCDynamic::GetObjectsLocalLibrary() const
  1413.     {
  1414.         return ::GetObjectsLocalLibrary(this);
  1415.     }
  1416.  
  1417.     inline TLibraryFile* TSCDynamic::GetObjectsLocalLibraryFile() const
  1418.     {
  1419.         return ::GetObjectsLocalLibraryFile(this);
  1420.     }
  1421.  
  1422.     inline TStandardPool* TSCDynamic::GetObjectsLocalPool() const
  1423.     {
  1424.         return ::GetObjectsLocalPool(this);
  1425.     }
  1426.  
  1427.     inline void TSCDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1428.     {
  1429.         ::SetObjectsLocalPool(this, pool);
  1430.     }
  1431.     
  1432. /*    -------------------------------------------------------------------------
  1433.     Inline methods for TSCSimpleDynamic
  1434.     ------------------------------------------------------------------------- */
  1435.  
  1436.     inline const TClassID& TSCSimpleDynamic::GetObjectsClassID() const
  1437.     {
  1438.         return ((const TSCDynamic*)this)->GetObjectsClassID();
  1439.     }
  1440.  
  1441.     inline const TClassID& TSCSimpleDynamic::GetObjectsParentClassID() const
  1442.     {
  1443.         return ((const TSCDynamic*)this)->GetObjectsParentClassID();
  1444.     }
  1445.  
  1446.     inline unsigned short TSCSimpleDynamic::GetObjectsVersion() const
  1447.     {
  1448.         return ::GetObjectsVersion(this);
  1449.     }
  1450.  
  1451.     inline unsigned short TSCSimpleDynamic::GetObjectsMinVersion() const
  1452.     {
  1453.         return ::GetObjectsMinVersion(this);
  1454.     }
  1455.  
  1456.     inline size_t TSCSimpleDynamic::GetObjectsSize() const
  1457.     {
  1458.         return ((const TSCDynamic*)this)->GetObjectsSize();
  1459.     }
  1460.  
  1461.     inline TLibrary* TSCSimpleDynamic::GetObjectsLocalLibrary() const
  1462.     {
  1463.         return ((const TSCDynamic*)this)->GetObjectsLocalLibrary();
  1464.     }
  1465.  
  1466.     inline TLibraryFile* TSCSimpleDynamic::GetObjectsLocalLibraryFile() const
  1467.     {
  1468.         return ((const TSCDynamic*)this)->GetObjectsLocalLibraryFile();
  1469.     }
  1470.  
  1471.     inline TStandardPool* TSCSimpleDynamic::GetObjectsLocalPool() const
  1472.     {
  1473.         return ((const TSCSimpleDynamic*)this)->GetObjectsLocalPool();
  1474.     }
  1475.  
  1476.     inline void TSCSimpleDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1477.     {
  1478.         ((const TSCSimpleDynamic*)this)->SetObjectsLocalPool(pool);
  1479.     }
  1480.  
  1481.     inline Boolean TSCSimpleDynamic::IsDerivedFrom(const TClassID& id) const
  1482.     {
  1483.         return ((const TSCSimpleDynamic*)this)->IsDerivedFrom(id);
  1484.     }
  1485.     
  1486. #endif        /* __SC__ */
  1487. #endif        /* __cplusplus */
  1488.  
  1489. /*******************************************************************************
  1490. ** EXCEPTION Handling
  1491. **
  1492. ** Some RULES:
  1493. ** 1) Never propogate a failure outside of a constructor or destructor.
  1494. **    If your constructor or destructor can call something which fails, it
  1495. **    _must_ CATCH the failure and not re-propogate it.
  1496. ** 2) Never create an object inside of a "try" block which you cannot 
  1497. **    destroy (especially an auto object).
  1498. ** 3) if you are going to just RERAISE the exception, or Fail 
  1499. **      with a different error, you must manually call the destructors 
  1500. **    of any  auto objects that are still in scope!
  1501. ** 4) Any variables that are changed inside the "try", and which are tested
  1502. **    inside a CATCH, CATCH_ALL, or FINALLY must be declared "VOLATILE" 
  1503. **      (Use the VOLATILE macro above until C++ and volatile work!)
  1504. ** 5) Never call Fail while an auto variable is in scope - it's 
  1505. **      destructor will not be called unless you call it manually.
  1506. ** 6) FINALLY is always entered after TRY unless a CATCH clause raises
  1507. **    (or re-raises) an exception (this is true even if an exception was
  1508. **    not thrown).
  1509. ********************************************************************************/
  1510.  
  1511. typedef struct TException    TException;
  1512.  
  1513. struct TException
  1514. {
  1515.     TException*            fPrev;
  1516.     size_t                fReserved;
  1517. #if GENERATINGPOWERPC
  1518.     long                fBuffer[33];
  1519. #endif
  1520. #if GENERATING68K
  1521.     long                fBuffer[12];
  1522. #endif
  1523.     char*                fMessage;
  1524.     void*                fPtr;
  1525.     OSErr                fError;
  1526. };
  1527.  
  1528. #ifdef __cplusplus
  1529. extern "C" {
  1530. #endif
  1531.  
  1532. void        PushException(TException*);
  1533. TException*    PopException(TException*);
  1534. Boolean        MatchException(TException*, long);
  1535.  
  1536. #if GENERATING68K
  1537.     #pragma parameter __D0 SetupException(__A0)
  1538.     int SetupException(long* val) =
  1539.     {
  1540.         0x43fa, 0x0008,    /* lea        *+10,a1 */
  1541.         0x48d0, 0xdefc,    /* movem.l    d2-d7/a1-a4/a6/a7,(a0) */
  1542.         0x7000            /* moveq    #0,d0 */
  1543.     };
  1544. #else
  1545.     int SetupException(long* val);
  1546. #endif
  1547.  
  1548. #ifdef __cplusplus
  1549. }
  1550. #endif
  1551.     
  1552. /*    -----------------------------------------------------------------
  1553.     Some important functions for exception handling
  1554.     ----------------------------------------------------------------- */
  1555.  
  1556. #ifdef __cplusplus
  1557. extern "C" {
  1558.     void Fail(long err, const char* msg=NULL);
  1559. }
  1560. #else
  1561.     void Fail(long err, const char* msg);
  1562. #endif
  1563.  
  1564. #ifdef __cplusplus
  1565.     inline void FailNULL(void* val, long err, const char* msg=NULL) 
  1566.     { 
  1567.         if (val == 0) 
  1568.             Fail(err, msg); 
  1569.     }
  1570. #else
  1571.     #define FailNULL(val, err, msg)        \
  1572.         if (val == 0) { Fail(err, msg); } else {}
  1573. #endif
  1574.  
  1575. #if qDebug
  1576.     #define DebugFail(err, msg)                Fail(err, msg)
  1577.     #define DebugFailNULL(ptr, err, msg)    FailNULL(ptr, err, msg)
  1578. #else
  1579.     #define DebugFail(err, msg)                Fail(err, NULL)
  1580.     #define DebugFailNULL(ptr, err, msg)    FailNULL(ptr, err, NULL)
  1581. #endif
  1582.  
  1583.  
  1584. #define ErrorCode()                 (except.fError)
  1585. #define ErrorMessage()                (except.fMessage)
  1586.  
  1587. /*    -----------------------------------------------------------------
  1588.     The RAISE/RERAISE/TRY/CATCH/CATCH_ALL/FINALLY/ENDTRY macros
  1589.     ----------------------------------------------------------------- */
  1590.  
  1591. #define RAISE(x)    Fail(x,NULL)
  1592.         
  1593. #define RERAISE        Fail(ErrorCode(), ErrorMessage())
  1594.  
  1595. #define TRY                                                 \
  1596.     {                                                        \
  1597.         Boolean        finallyUsed = false;                    \
  1598.         TException    except;                                    \
  1599.         VOLATILE(finallyUsed);                                \
  1600.         VOLATILE(except);                                    \
  1601.         PushException(&except);                                \
  1602.         if (SetupException(except.fBuffer) == 0)            \
  1603.         {
  1604.         
  1605. #define CATCH(e)                                            \
  1606.         }                                                    \
  1607.         else if (MatchException(&except, e))                \
  1608.         { 
  1609.         
  1610.         
  1611. #define CATCH_ALL                                            \
  1612.         }                                                    \
  1613.         else                                                \
  1614.         { 
  1615.         
  1616.         
  1617. #define FINALLY                                                \
  1618.         }                                                    \
  1619.         PopException(&except);                                \
  1620.         finallyUsed = true;                                    \
  1621.         {
  1622.         
  1623. #define ENDTRY                                                \
  1624.         }                                                    \
  1625.         PopException(&except);                                \
  1626.         if (finallyUsed)                                    \
  1627.             if (ErrorCode() != kNoError) RERAISE;            \
  1628.     }
  1629.  
  1630. #endif
  1631.